home *** CD-ROM | disk | FTP | other *** search
/ Programmer Power Tools / Programmer Power Tools.iso / progjrn / pj_7_6.arc / WINDEV.ARC / WNTFNS.C < prev    next >
C/C++ Source or Header  |  1989-07-30  |  4KB  |  133 lines

  1. /*
  2.  * WNTERM function support module
  3.  *
  4.  * Written by
  5.  * William S. Hall
  6.  * 3665 Benton Street, #66
  7.  * Santa Clara, CA 95051
  8. */
  9.  
  10. #define NOKANJI
  11. #define NOATOM
  12. #define NOSOUND
  13. #include <windows.h>
  14. #include <ascii.h>
  15. #include <string.h>
  16. #include "ttycls.h"
  17. #include "wnterm.h"
  18.  
  19. /* paint the main window */
  20. void NEAR MainWndPaint(hWnd, lpps)
  21. HWND hWnd;
  22. LPPAINTSTRUCT lpps;
  23. {
  24.  
  25.     HDC hDC = lpps->hdc;
  26.  
  27.   // if the window is iconic, draw in the icon area
  28.     if (IsIconic(hWnd)) {
  29.     RECT rIcon;
  30.     GetClientRect(hWnd, (LPRECT)&rIcon);
  31.     Rectangle(hDC, 0,0,rIcon.right, rIcon.bottom);
  32.         TextOut(hDC,2,rIcon.bottom/3,(LPSTR)szIconTitle,strlen(szIconTitle));
  33.     }
  34.   // otherwise update the text in the window
  35.     else 
  36.     TTYWndPaint(&MWnd, lpps->hdc, lpps->rcPaint.top, lpps->rcPaint.bottom);
  37. }
  38.  
  39. /* come here to handle menu items */
  40. void NEAR WndCommand(hWnd, menuitem, param)
  41. HWND hWnd;
  42. WORD menuitem;
  43. LONG param;
  44. {
  45.  
  46.     HMENU hMenu;
  47.     FARPROC fp;
  48.  
  49.     switch (menuitem) {
  50.     case IDM_ABOUT:        // create the about box
  51.         fp = MakeProcInstance((FARPROC)AboutBoxProc, hInst);
  52.         DialogBox(hInst, MAKEINTRESOURCE(DT_ABOUT),hWnd,fp);
  53.         FreeProcInstance(fp);
  54.         break;
  55.  
  56.     case IDM_OFFLINE:
  57.       // if currently offline, then change the window proc
  58.       // over to the subclass window procedure.
  59.         SetWindowLong(hWnd, GWL_WNDPROC, (LONG)MainWndSubProc);
  60.       // rewrite the menu bar.
  61.         hMenu = GetMenu(hWnd);
  62.         ChangeMenu(hMenu,IDM_OFFLINE,(LPSTR)szOnLine,IDM_ONLINE,
  63.             MF_BYCOMMAND | MF_CHANGE);
  64.         DrawMenuBar(hWnd);
  65.       // indicate that we are online.
  66.         LineState = IDM_ONLINE;
  67.         break;
  68.  
  69.     case IDM_ONLINE:
  70.       // if currently online, reset the window proc.
  71.         SetWindowLong(hWnd, GWL_WNDPROC, (LONG)MainWndProc);
  72.       // redraw the menu.
  73.         hMenu = GetMenu(hWnd);
  74.         ChangeMenu(hMenu,IDM_ONLINE,(LPSTR)szOffLine,IDM_OFFLINE,
  75.             MF_BYCOMMAND | MF_CHANGE);
  76.         DrawMenuBar(hWnd);
  77.       // show new state.
  78.         LineState = IDM_OFFLINE;
  79.         break;
  80.  
  81.     case IDM_COMM:    // make communications settings.
  82.         fp = MakeProcInstance((FARPROC)SetCommParams, hInst);
  83.         DialogBox(hInst, MAKEINTRESOURCE(DT_COMM),hWnd, fp);
  84.         FreeProcInstance(fp);
  85.         break;
  86.  
  87.     case IDM_LOCAL:    // set local echo.
  88.         hMenu = GetMenu(hWnd);
  89.         if (MWnd.LocalEcho) {
  90.         MWnd.LocalEcho = FALSE;
  91.         CheckMenuItem(hMenu, menuitem, MF_UNCHECKED);
  92.         }
  93.         else {        
  94.         MWnd.LocalEcho = TRUE;
  95.         CheckMenuItem(hMenu, menuitem, MF_CHECKED);
  96.         }        
  97.         break;
  98.  
  99.     case IDM_CLEAR:    // clear the screen.
  100.         HideCaret(hWnd);
  101.         TTYClear(&MWnd);
  102.         SetCaretPos(MWnd.Pos.x, MWnd.Pos.y);
  103.         ShowCaret(hWnd);
  104.         break;
  105.     }
  106. }
  107.  
  108. /* come here to read the communications buffer if no messages to process */
  109. void NEAR ProcessComm()
  110. {
  111.  
  112.     COMSTAT ComStatus;
  113.     int num;
  114.     int result = 0;
  115.     int room = BUFSIZE - Buflen;    // check for space
  116.  
  117.     if ((LineState == IDM_ONLINE) && (!ScrollLock)) {
  118.     if (room > 0) {
  119.             GetCommError(cid, (COMSTAT FAR *)&ComStatus);
  120.             if (num = ComStatus.cbInQue) {    // read number in comm queue.
  121.             num = min(num, room);    // select the smaller value
  122.             if ((result = ReadComm(cid,(LPSTR)(Buffer + Buflen), num)) < 0)
  123.                 result = -result;
  124.         Buflen += result;
  125.             // note, we ignore read errors 
  126.             // so result is set to its absolute value.
  127.         }
  128.     }
  129.     }
  130.     if (Buflen)
  131.     PostMessage(MWnd.hWnd, WM_USER, Buflen, 0L);
  132. }
  133.